home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / developer-tools / andere sprachen / perl5 / perl5.002 / installman < prev    next >
Encoding:
Text File  |  1996-02-12  |  4.7 KB  |  166 lines

  1. #!./perl
  2. BEGIN { @INC = ('lib') }
  3. use Config;
  4. use Getopt::Long;
  5. use File::Find;
  6. use File::Path qw(mkpath);
  7. require Cwd;
  8.  
  9. umask 022;
  10.  
  11. $ver = $];
  12. $release = substr($ver,0,3);   # Not used presently.
  13. $patchlevel = substr($ver,3,2);
  14. die "Patchlevel of perl ($patchlevel)",
  15.     "and patchlevel of config.sh ($Config{'PATCHLEVEL'}) don't match\n"
  16.     if $patchlevel != $Config{'PATCHLEVEL'};
  17.  
  18. $usage =
  19. "Usage:  installman --man1dir=/usr/wherever --man1ext=1
  20.                     --man3dir=/usr/wherever --man3ext=3
  21.             --notify --help
  22.     Defaults are:
  23.     man1dir = $Config{'installman1dir'};
  24.     man1ext = $Config{'man1ext'};
  25.     man3dir = $Config{'installman3dir'};
  26.     man3ext = $Config{'man3ext'};
  27.     --notify (or -n) just lists commands that would be executed.\n";
  28.  
  29. GetOptions( qw( man1dir=s man1ext=s man3dir=s man3ext=s notify n help)) 
  30.     || die $usage;
  31. die $usage if $opt_help;
  32.  
  33. # These are written funny to avoid -w typo warnings.
  34. $man1dir = defined($opt_man1dir) ? $opt_man1dir : $Config{'installman1dir'};
  35. $man1ext = defined($opt_man1ext) ? $opt_man1ext : $Config{'man1ext'};
  36. $man3dir = defined($opt_man3dir) ? $opt_man3dir : $Config{'installman3dir'};
  37. $man3ext = defined($opt_man3ext) ? $opt_man3ext : $Config{'man3ext'};
  38.  
  39. $notify = $opt_notify || $opt_n;
  40.  
  41. #Sanity checks
  42.  
  43. -x  "./perl"    || warn "./perl not found!  Have you run make?\n";
  44. -d  $Config{'installprivlib'}
  45.     || warn "Perl library directory $Config{'installprivlib'} not found.
  46.         Have you run make install?.  (Installing anyway.)\n";
  47. -x 't/TEST'        || warn "WARNING: You've never run 'make test'!!!",
  48.     "  (Installing anyway.)\n";
  49.  
  50. # Install the main pod pages.
  51. runpod2man('pod', $man1dir, $man1ext);
  52.  
  53. # Install the pods for library modules.
  54. runpod2man('lib', $man3dir, $man3ext);
  55.  
  56. sub runpod2man {
  57.     my($poddir, $mandir, $manext) = @_;
  58.     my($builddir) = Cwd::getcwd();
  59.  
  60.     if ($mandir eq ' ' or $mandir eq '') {
  61.     print STDERR "Skipping installation of $poddir man pages.\n";
  62.     return;
  63.     }
  64.  
  65.     chdir $poddir || die "Unable to cd to $poddir directory!\n$!\n";
  66.  
  67.     # We insist on using the current version of pod2man in case there
  68.     # are enhancements or changes from previous installed versions.
  69.     # The error message doesn't include the '..' because the user
  70.     # won't be aware that we've chdir to $poddir.
  71.     -x  "../pod/pod2man" || die "Executable pod/pod2man not found.\n";
  72.  
  73.     # We want to be sure to use the current perl.  We can't rely on
  74.     # the installed perl because it might not be actually installed
  75.     # yet. (The user may have set the $install* Configure variables 
  76.     # to point to some temporary home, from which the executable gets
  77.     # installed by occult means.)
  78.     $pod2man = "../perl -I ../lib ../pod/pod2man --section=$manext --official";
  79.  
  80.     mkpath($mandir, 1, 0777);  # In File::Path
  81.     # Make a list of all the .pm and .pod files in the directory.  We will
  82.     # always run pod2man from the lib directory and feed it the full pathname
  83.     # of the pod.  This might be useful for pod2man someday.
  84.     @modpods = ();
  85.     find(\&lsmodpods, '.');
  86.     foreach $mod (@modpods) {
  87.     $manpage = $mod;
  88.     # Convert name from  File/Basename.pm to File::Basename.3 format,
  89.     # if necessary.
  90.     $manpage =~ s#\.p(m|od)$##;
  91.     $manpage =~ s#/#::#g;
  92.     $manpage = "${mandir}/${manpage}.${manext}";
  93.     &cmd("$pod2man $mod > $manpage.tmp");
  94.     if (-s "$manpage.tmp") {
  95.         rename("$manpage.tmp", $manpage) && next;
  96.         warn "cannot rename to $manpage: $!";
  97.     }
  98.     print STDERR "unlink $manpage.tmp\n";
  99.     unless ($notify) {
  100.         unlink("$manpage.tmp") || warn "cannot unlink $manpage.tmp: $!";
  101.     }
  102.     }
  103.     chdir "$builddir" || die "Unable to cd back to $builddir directory!\n$!\n";
  104. }
  105.  
  106. sub lsmodpods {
  107.     my $dir  = $File::Find::dir;
  108.     my $name = $File::Find::name;
  109.     if (-f $_) {
  110.         $name =~ s#^\./##;
  111.     push(@modpods, $name) if ($name =~ /\.p(m|od)$/);
  112.     }
  113. }
  114.  
  115. print STDERR "  Installation complete\n";
  116.  
  117. exit 0;
  118.     
  119.  
  120. ###############################################################################
  121. # Utility subroutines from installperl
  122.  
  123. sub cmd {
  124.     local($cmd) = @_;
  125.     print STDERR "  $cmd\n";
  126.     unless ($notify) {
  127.     if ($Config{d_fork}) {
  128.         fork ? wait : exec $cmd;  # Allow user to ^C out of command.
  129.     }
  130.     else {
  131.         system $cmd;
  132.     }
  133.     warn "Command failed!!\n" if $?;
  134.     }
  135.     return $? != 0;
  136. }
  137.  
  138. sub link {
  139.     local($from,$to) = @_;
  140.  
  141.     print STDERR "  ln $from $to\n";
  142.     link($from,$to) || warn "Couldn't link $from to $to: $!\n" unless $notify;
  143. }
  144.  
  145. sub chmod {
  146.     local($mode,$name) = @_;
  147.  
  148.     printf STDERR "  chmod %o %s\n", $mode, $name;
  149.     chmod($mode,$name) || warn sprintf("Couldn't chmod %o %s: $!\n",$mode,$name)
  150.     unless $notify;
  151. }
  152.  
  153. sub samepath {
  154.     local($p1, $p2) = @_;
  155.     local($dev1, $ino1, $dev2, $ino2);
  156.  
  157.     if ($p1 ne $p2) {
  158.     ($dev1, $ino1) = stat($p1);
  159.     ($dev2, $ino2) = stat($p2);
  160.     ($dev1 == $dev2 && $ino1 == $ino2);
  161.     }
  162.     else {
  163.     1;
  164.     }
  165. }
  166.